#### plotting means and error bars with ggplot2
library("ggplot2")
library("plyr")
# Run the functions length, mean, and sd on the value of "value" for each group, 
# broken down by sex + condition
setwd("G:/ghelin project")
library(readxl)
test <- read_excel("raw data1.xlsx")
head(test)



data <- test
cdata <- ddply(data, c("group", "time_point"), summarise,
               N    = length(value),
               mean = mean(value),
               sd   = sd(value),
               se   = sd / sqrt(N)
)
cdata
p1 <- ggplot(cdata, aes(x= time_point, y = mean, group = group, color = group))
p1 + geom_line()+
  geom_point(size=2)+
 geom_errorbar(aes(x=time_point, ymin=mean-sd, ymax=mean+sd), width=0.4)+
  xlab("Time points")+
  ylab("Latency (s)")
###### save files in pdf and tiff formats#####
ggsave("CLP_LATENCY_LINEPLOT.pdf")
ggsave("CLP_LATENCY_LINEPLOT.tiff")
ggsave("CLP_LATENCY_LINEPLOT.emf")

